package org.aileen.springbook.Mapper;

import org.aileen.springbook.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {

    @Insert("INSERT INTO book_info (book_name, author, count , price ,publish, `status`) VALUES (" +
            "#{bookName}, #{author},#{count} , #{price} ,  #{publish}, #{status})")
    Integer insertBook(BookInfo bookInfo);

    //获取所有可借阅图书的条数
    @Select("select count(*) from book_info where status != 0")//查询所有可借阅图书的条数的方法实现
    Integer count();//方法声明

    //根据页码获取可借阅图书列表
    @Select("select * from book_info where status != 0 order by id desc limit #{offset} , #{limit} ")
    List<BookInfo> getListByPage(Integer offset , Integer limit);//方法声明

    //根据图书ID获取图书信息
    @Select("select * from book_info where id = #{bookId}")
    BookInfo getBookInfo(Integer bookId);

    //更新图书信息 -> 更新图书信息需要动态修改SQL语句,所以可以将SQL语句写在mapper的XML文件中
    Integer updateBook(BookInfo bookInfo);

    //批量删除图书,也是通过动态SQL来实现
    Integer batchDelete(List<Integer> ids);//循环的需要删除的图书列表集合叫ids




}



